package pers.cj.pdos.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import pers.cj.pdos.cache.CacheData;
import pers.cj.pdos.cache.CacheRemove;
import pers.cj.pdos.entity.Role;
import pers.cj.pdos.entity.ShopGuide;
import pers.cj.pdos.mapper.ShopGuideMapper;
import pers.cj.pdos.service.IShopGuideService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import pers.cj.pdos.utils.Utils;
import pers.cj.pdos.vo.ShopGuideVo;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenj
 * @since 2019-11-04
 */
@Service
public class ShopGuideServiceImpl extends ServiceImpl<ShopGuideMapper, ShopGuide> implements IShopGuideService {
    @Autowired
    ShopGuideMapper shopGuideMapper;
    @Override
    public List<ShopGuideVo> listVoPage(int page, int limit, String companyId, String searchStoreId, Integer status, String searchContent) {
        return shopGuideMapper.listVoPage(Utils.genPage(page,limit),limit,companyId,searchStoreId,status,Utils.genLikeData(searchContent));
    }

    @Override
    public long count(String companyId, Integer status) {
        QueryWrapper<ShopGuide> wrapper = new QueryWrapper<>();
        wrapper.eq("company_id",companyId);
        if (status != null) {
            wrapper.eq("status",status);
        }
        return shopGuideMapper.selectCount(wrapper);
    }

    @Override
    public boolean checkName(String name, String companyId) {
        return shopGuideMapper.selectCount(new QueryWrapper<ShopGuide>().eq("company_id",companyId).eq("name",name)) > 0;
    }

    @Override
    @CacheData(clazz = ShopGuideServiceImpl.class,param = "#id")
    public ShopGuideVo getVoById(String id) {
        return shopGuideMapper.getVoById(id);
    }

    @Override
    public void insert(ShopGuide shopGuide) {
        shopGuideMapper.insert(shopGuide);
    }

    @Override
    @CacheRemove(clazz = ShopGuideServiceImpl.class, methodName = "getVoById",param = "#shopGuide.id")
    public void remove(ShopGuide shopGuide) {
        shopGuideMapper.deleteById(shopGuide);
    }

    @Override
    @CacheRemove(clazz = ShopGuideServiceImpl.class, methodName = "getVoById",param = "#shopGuide.id")
    public void update(ShopGuide shopGuide) {
        shopGuideMapper.updateById(shopGuide);
    }
}
